home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: class declaration question
- Date: Sun, 21 Jan 1996 12:31:27 GMT
- Organization: Netcom
- Message-ID: <3102311d.216834688@nntp.ix.netcom.com>
- References: <4dphp6$1bp@noc2.drexel.edu> <Robert.Lendvai-2101960127070001@129.170.80.94>
- NNTP-Posting-Host: ix-dc10-02.ix.netcom.com
- X-NETCOM-Date: Sun Jan 21 4:31:14 AM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- Robert.Lendvai@dartmouth.edu (Robert Lendvai) wrote:
-
- > In article <4dphp6$1bp@noc2.drexel.edu>, st918h5w@dunx1.ocs.drexel.edu
- > (Jonathan Juniman) wrote:
- >
- > > Is it necessary to do this:
- > >
- > > class SomeClass
- > > {
- > > public:
- > > void Somefunction(int SomeParameter);
- > > }
- > >
- > > or is it just as legal to do this:
- > > class SomeClass
- > > {
- > > public:
- > > void SomeFunction(int);
- > > }
- > >
- > > The latter seems to be the convention, but why does the compiler need to
- > > know the name of SomeFunction's argument? Isn't it sufficient to know the
- > > type of Somefunction's argument (namely, int)?
- > >
- > > Please reply by e-mail. PS; thanks to all the people who answered my
- > > overloaded operator question.
- > >
- > > Jon
- >
- > John,
- >
- > i think you need to go with the former (int SomeParameter). I'm not
- > sure if the other way is legal, but even so, you need to know the name of
- > the argument so that you may manipulate it in the function definition.
- > Otherwise, how would you refer to the argument's value.
-
- You don't refer to the argument's value. This is a declaration of the
- member function, not a definition. There is no body in which to refer
- to the argument's value.
-
- In a (member) function definition, you must supply the parameter name
- if you want to use it in the function body. Occasionally you have a
- function with a parameter that is not used and in that case it is not
- necessary to give it a name.
-
- The name may be omitted in a declaration and supplied in the
- definition for the same function. Or it may be different in the two.
-
- Either of the above is legal and choice is really a matter of style.
- Some compilers will give better error messages if a meaningful name is
- given to the parameter so I prefer to do so.
-
-
- Michael M Rubenstein
-